package com.yuwen.yuwenRPC.serializer;

/**
 * @ClassNameSerializerFactory
 * @Description TODO
 * @Author钰玟
 * @Date2025/3/30 下午7:05
 * @Version 1.0
 **/

import com.yuwen.yuwenRPC.spi.SpiLoader;

/**
 * 序列化器工厂
 */
public class SerializerFactory {
    /**
     * 序列化映射(用于单例)
     */
//    @Deprecated
//    private static final Map<String, Serializer> KEY_SERIALIZER_MAP = new HashMap<String, Serializer>(){{
//            put(SerializerKeys.JDK, new JdkSerializer());
//            put(SerializerKeys.JSON,new JsonSerializer());
//            put(SerializerKeys.KRYO,new KryoSerializer());
//            put(SerializerKeys.HESSIAN,new HessianSerializer());
//        }};

    /**
     * 静态代码块加载 Serializer  得实现类
     */
    static {
        SpiLoader.load(Serializer.class);
    }

    /**
     * 默认的序列化器 Jdk序列化器
     */
//    @Deprecated
//    private static final Serializer DEFAULT_SERIALIZER = KEY_SERIALIZER_MAP.get(SerializerKeys.JDK);


    private static final Serializer DEFAULT_SERIALIZER = new JdkSerializer();


    /**
     * 获取指定Key的序列化器
     * @param key
     * @return
     */
    public static Serializer getSerializer(String key) {
//        @Deprecated
//        return KEY_SERIALIZER_MAP.getOrDefault(key,DEFAULT_SERIALIZER);
        return SpiLoader.getInstance(Serializer.class,key);

    }


}
